home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / SIZE.C < prev    next >
Text File  |  1992-12-02  |  5KB  |  163 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "ShellPub.h"
  59. #include    "Path.h"
  60.  
  61. /*******************************************************************
  62.  *
  63.  *    Function SIZE
  64.  *
  65.  *    PathName Callback function
  66.  *
  67.  *    usage SIZE [options] [names]    
  68.  *
  69.  *
  70.  *******************************************************************/
  71.  
  72. void        SIZECallBack( WHandle ShellWh, int16 ProcID, char *path,
  73.                 char *last, pathType what, int16 vRefNum, int32 dirID )
  74. {
  75. HFileInfo    pb;
  76. OSErr        err;
  77. char        str[ 256 ];
  78.  
  79.     if( what == pathIsFile )
  80.         {
  81.         strcpy( str, last );
  82.         CtoPstr( str );
  83.         
  84.         pb.ioCompletion = NULL;
  85.         pb.ioNamePtr     = (StringPtr) str;
  86.         pb.ioVRefNum    = vRefNum;
  87.         pb.ioFDirIndex    = 0;
  88.         pb.ioDirID        = dirID;
  89.         
  90.         err = PBHGetFInfo( &pb, FALSE );
  91.         
  92.         if( err )
  93.             {
  94.             procPrintf( ShellWh, ProcID,
  95.                     "size : can't get info for %s (%d)\n", last, err );
  96.             return;
  97.             }
  98.             
  99.         procPrintf( ShellWh, ProcID,
  100.             "%ps\n  Data     : %6ld\n  Resource : %6ld\n",
  101.             str, pb.ioFlLgLen, pb.ioFlRLgLen );
  102.         }
  103. }
  104.  
  105. /*******************************************************************/
  106.  
  107. void        SIZEFile( WHandle ShellWh, int16 ProcID, char *argument )
  108. {
  109. ShellWindRec    **MyShell;
  110.  
  111.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  112.  
  113.     ExpandPath( ShellWh, ProcID, argument, (ProcPtr) SIZECallBack,
  114.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  115.  
  116.     ResetShellPWD( ShellWh );
  117. }
  118.  
  119. /*******************************************************************/
  120.  
  121. Boolean            DoSIZE( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  122.                     char *string )
  123. {
  124. int16            i, argc;
  125. char            argument[ 256 ];
  126. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  127.  
  128.     switch( ProcToken )
  129.         {
  130.         case    PROC_INIT    :
  131.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  132.             break;
  133.             
  134.         case    PROC_TERM    :
  135.         case    PROC_BREAK    :
  136.             /* Tell the shell that we're done */
  137.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  138.             /* Turn ourself off */
  139.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  140.             break;
  141.             
  142.         case    PROC_STDIN    :
  143.             if( (**MyShell).Proc[ ProcID ].flags )
  144.                 {
  145.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  146.  
  147.                 /* get arguments */
  148.                 argc = (**MyShell).Proc[ ProcID ].argc;
  149.                 for( i = 1; i < argc; i++ )
  150.                     {
  151.                     GetArgv( ShellWh, ProcID, i, argument );
  152.                     SIZEFile( ShellWh, ProcID, argument );
  153.                     }
  154.  
  155.                 /* Tell the shell that we're done */
  156.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  157.                 
  158.                 /* Turn ourself off */
  159.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  160.                 return( FALSE );
  161.                 }
  162.         }
  163. }